﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace Medicine.Activities
{
    [Activity(Label = "即将过期药品信息")]
    public class ExpiredInfoActivity : QueryInfoBaseActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.AllInfoLayout);
            SetInitControl(this, Resource.Id.allListView, Resource.Id.sw);

            SetData();
        }

        private void SetData()
        {
            var startDate = DateTime.Now;
            //var allData = DbContext.DbC.ListQuery<Models.Medicine>(s => s.ExpirationDate != null && s.ExpirationDate > startDate);
            //var overData = new List<Models.Medicine>();
            //foreach (var item in allData)
            //{
            //    var overDate = Convert.ToDateTime(item.ExpirationDate);
            //    if (overDate > startDate)
            //        continue;

            //    overData.Add(item);
            //}
            (_listView.Adapter as Medicine.Models.MedicineAdapter).SetQueryExpression(s => s.ExpirationDate != null && s.ExpirationDate > startDate);
            (_listView.Adapter as Medicine.Models.MedicineAdapter).NotifyDataSetChanged();
        }
    }
}